package com.live.stamp.base.validation;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.container.core.common.BusinessException;

import java.util.Collection;

/**
 * 集合验证处理器
 */
public class CollectionHandle extends ParamHandler {
    private static final Logger logger = LoggerFactory.getLogger(CollectionHandle.class);

    @Override
    protected ValidationEnum getParamHandleType() {
        return ValidationEnum.COLLECTION;
    }

    @Override
    protected void echo(String paramName, Object param) {
        Collection c = (Collection)param;
        if(c == null){
            logger.error("CollectionHandle class -> param:{} is null!", paramName);
            throw new BusinessException(String.format("参数%s为空", paramName));
        }
        if(c.isEmpty()){
            logger.error("CollectionHandle class -> collection:{} is empty!", paramName);
            throw new BusinessException(String.format("集合%s为空", paramName));
        }
    }
}
